#pragma once
#include <iostream>
#include <assert.h>

using namespace std;

class Stack
{
public:
	Stack()
	{
		arr = new int[4];
		top = 0;
		capacity = 4;
	}
	void Print()
	{
		for (int i = 0; i < top; i++)
		{
			cout << arr[i] << " ";
		}
		cout << endl;
	}
	void Push(int x)
	{
		if (top == capacity)
		{
			int* ptr = new int[2 * capacity];
			for (int i = 0; i < top; i++)
			{
				ptr[i] = arr[i];
			}
			delete[] arr;
			arr = ptr;
			capacity *= 2;
		}
		arr[top] = x;
		top++;
	}
	void Pop()
	{
		assert(top > 0);
		arr[top - 1] = 0;
		top--;
	}
	bool Empty()
	{
		return top == 0;
	}
	int Size()
	{
		return top;
	}
	int Top()
	{
		return arr[top - 1];
	}

	~Stack()
	{
		delete[] arr;
		arr = nullptr;
		top = 0;
		capacity = 0;
	}
private:
	int* arr;
	int top;
	int capacity;
};